package com.ybkj.daijia.api.apirest.v4;

import com.ybkj.daijia.serverUtils.SettingUtils;
import com.ybkj.daijia.api.driver.transport.ResultTransport;
import com.ybkj.daijia.api.util.ErrorConstantV4;
import com.ybkj.daijia.server.model.Area;
import com.ybkj.daijia.server.service.AreaService;
import com.ybkj.daijia.server.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller("ApiCompanyProcessControllerV4")
@RequestMapping(value = "api/company/v4/")
public class CompanyProcessController {

    @Autowired
    private CompanyService companyService;

    @Autowired
    private AreaService areaService;

    @Autowired
    private SettingUtils settingUtils;


    @RequestMapping(value = "findChargeStartTimes")
    public @ResponseBody
    ResultTransport findChargeStartTimes(Long areaId) {

        if (null == areaId) {
            return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
        }

        try {

            Area area = areaService.findOneWithCharge(areaId);

            ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
            instance.setData(area.getChargeStartTimes());

            return instance;

        } catch (Exception e) {
            return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
        }
    }

    @RequestMapping(value = "findAreaName")
    public @ResponseBody
    ResultTransport findAreaName(Long areaId) {

        if (null == areaId) {
            return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
        }
        try {
            Area area = areaService.findOne(areaId);
            ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
            instance.setData(area.getName());
            return instance;
        } catch (Exception e) {
            return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
        }
    }
}
